{% extends "pub_base.html" %}
{% load seahub_tags avatar_tags group_avatar_tags i18n %}
{% load url from future %}

{% block cur_lib %}tab-cur{% endblock %}

{% block right_panel %}
<div class="hd ovhd">
    <h3 class="fleft">{% trans "Libraries" %}</h3>
    <button id="repo-create" class="fright"><img src="{{ MEDIA_URL }}img/add.png" alt="" class="add vam" /><span class="vam">{% trans "New Library"%}</span></button>
</div>
{% if public_repos %}
<table>
    <tr>
        <th width="4%"></th>
        <th width="20%">{% trans "Name"%} <span id="pub-repo-list-name-down" class="icon-caret-up cspt"></span> <span id="pub-repo-list-name-up" class="icon-caret-down cspt hide"></span></th>
        <th width="30%">{% trans "Description"%}</th>
        <th width="18%">{% trans "Last Update"%} <span id="pub-repo-list-time-up" class="icon-caret-up cspt hide"></span> <span id="pub-repo-list-time-down" class="icon-caret-down cspt"></span></th>
        <th width="15%">{% trans "Share From"%}</th>
        <th width="13%">{% trans "Operations"%}</th>
    </tr>
    {% for repo in public_repos %}
    <tr data-repo_name="{{repo.props.repo_name}}" data-time="{% if repo.props.last_modified %}{{ repo.props.last_modified }}{% else %}0{% endif %}">
        <td>
          {% if repo.encrypted %}
            <img src="{{MEDIA_URL}}img/sync-folder-encrypt-20.png" title="{% trans "Read-Write"%}" alt="{% trans "Directory icon"%}" />
          {% else %}
            {% if repo.user_perm == 'rw' %}
            <img src="{{MEDIA_URL}}img/sync-folder-20.png?t=1387267140" title="{% trans "Read-Write"%}" alt="{% trans "Directory icon"%}" />
            {% else %}
            <img src="{{MEDIA_URL}}img/folder-no-write-20.png?t=1387267140" title="{% trans "Read-Only"%}" alt="{% trans "Directory icon"%}" />
            {% endif %}
          {% endif %}
        </td>
        <td><a href="{% url 'repo' repo.props.repo_id %}">{{ repo.props.repo_name }}</a></td>
        <td>{{ repo.props.repo_desc }}</td>
        <td>{% if repo.props.last_modified %}{{ repo.props.last_modified|translate_seahub_time }}{% else %}--{% endif %}</td>
        <td>{{ repo.props.user|email2nickname }}</td>
        <td>
            {% if request.user.is_staff or repo.share_from_me %}
            <img src="{{MEDIA_URL}}img/rm.png" alt="" data-href="{% url 'unsetinnerpub' repo.repo_id %}" class="cancel-share op-icon vh" title="{% trans "Unshare" %}" />
            {% endif %}
        </td>
    </tr>
    {% endfor %}
</table>
{% else %}
<div class="empty-tips">
    <h2 class="alc">{% trans "No public library" %}</h2>
    <p>{% blocktrans %}You can create a public library by clicking "New Library" button, others can view and download this library.{% endblocktrans %}</p>
</div>
{% endif %}
{% include "snippets/repo_create_form.html" %}
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$(".cancel-share").click(function() {
    location.href = $(this).data('href');
});

function repoCreateSuccessCallback() {
    location.reload();
}
{% url 'public_repo_create' as repo_create_url %}
{% with post_url=repo_create_url %}
    {% include "snippets/repo_create_js.html" %}
{% endwith %}
{% include "snippets/sort_lib_js.html" %}
</script>
{% endblock %}
